/*
 *Description:
 *User:laoHu
 *Created with Intellij IDEA 2025
 *Data:2025.09.06
 *Time:21:31
 */

import javax.swing.text.html.HTMLDocument;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;

//Linkedlist的使用
public class Main{

    public static void main(String[] args) {
        LinkedList<Integer> linkedList = new LinkedList<>();

        linkedList.add(1);
        linkedList.add(2);

        for(int i = 0;i < linkedList.size();i++){
            System.out.print(linkedList.get(i) + " ");
        }

        System.out.println();
        System.out.println("======");
        linkedList.add(1,2);
        linkedList.addLast(3);

        for(int i = 0;i < linkedList.size();i++){
            System.out.print(linkedList.get(i) + " ");
        }
        System.out.println();
        System.out.println("====");
        for(int x : linkedList){
            System.out.print(x + " ");
        }

        System.out.println();
        System.out.println("=======");
        //迭代器遍历
        Iterator<Integer> iterator = linkedList.iterator();

        while(iterator.hasNext()){
            System.out.print(iterator.next() + " ");
        }
        System.out.println();
        System.out.println("=======");
        ListIterator<Integer> listIterator = linkedList.listIterator();
        while(listIterator.hasNext()){
            System.out.print(listIterator.next() + " ");
        }

        System.out.println();
        System.out.println("======");
        ListIterator<Integer> listIterator1 = linkedList.listIterator(linkedList.size());
        while(listIterator.hasPrevious()){
            System.out.print(listIterator.previous() + " ");
        }
    }
}

